<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
form_pr('getResults','','','post');
MYDCONN();
	if(!isset($_POST['RsDate'])) { $_POST['RsDate'] = date("Y-m-01"); }
	$GET = $GLOBALS['MYD']->db_array("SELECT ref, RsID, RsAmount, office_number AS OriNumero, IF(office_number=800,name,OriNombre) AS OriNombre 
		FROM systemoffice.main_offices
			INNER JOIN officeschema.origenes ON OriNumero = office_number
			LEFT OUTER JOIN finantial_results ON RsOri = office_number AND (RsOffice IS NULL OR RsOffice = ref) AND
			MONTH(RsDate) = MONTH('".$_POST['RsDate']."') AND YEAR(RsDate) = YEAR('".$_POST['RsDate']."') AND RsType = 2
			WHERE Type IN (1,2) AND (OriNumero = 800 OR 
				OriFechaAlta < '".$_POST['RsDate']."'
				AND (OriFechaBaja > '".$_POST['RsDate']."' OR OriFechaBaja IS NULL))
			ORDER BY OriNumero");
 ?>
<div class="title"> Resultados de Custos por Loja no periodo
	<?php
	mn_field('date','ED','RsDate',$_POST['RsDate'],'getResults','8','','');
	mn_field('button','ED','Consult','Consultar','','','','" style="padding:4px;margin:2px" onclick="
				document.getResults.action=\'Modules/CentrodeCustos/msetresult.php\';
				subform(\'getResults\',\'app\');');

	mn_field('button','ED','Consult','Validar','','','','" style="padding:4px;margin:2px" onclick="
				document.getResults.action=\'_response/rsproxy.php?pr=cdc_valvalues\';
				subform(\'getResults\',\'RsResponse\');'); ?>
	<div id="RsResponse"></div>
</div>
<table width="100%">
<tr style="cell-padding:5px;background-color:#F2F2F2"><td>Numero</td><td>Loja</td><td>Total de Despesas</td></tr>
<?php
 for($i=1;$i<=$GET[0];$i++) {
 	if($GET[$i]['RsAmount'] == ''){$GET[$i]['RsAmount']=0;}
 echo '<tr height="22px" bgcolor="'.gridlines($i).'"><td>';
	mn_field('hidden','ED','RsID'.$i,$GET[$i]['RsID'],'','','','');
	mn_field('hidden','ED','RsOffice'.$i,$GET[$i]['ref'],'','','','');
	mn_field('text','ED','OriNumero'.$i,$GET[$i]['OriNumero'],5,5,'','" readonly="'); echo '</td>
	<td>'.$GET[$i]['OriNombre'].'</td>
	<td>';
	mn_field('text','ED','RsAmount'.$i,$GET[$i]['RsAmount'],8,8,'','" style="text-align:right'); echo ' EUR</td>
    </tr>';
 } 
	mn_field('hidden','ED','RsCount',$GET[0],'','','','');
	mn_field('hidden','ED','RsType',2,'','','',''); ?>
</table>
</form>